/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.renderer;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import edu.mobbuzz.bean.Category;
import java.io.IOException;

/**
 *
 * @author irw
 */
public class CategoryRenderer extends Container implements ListCellRenderer {
    private Label nameLbl = new Label("");
    private Label descriptionLbl = new Label("");
    private Label pic = new Label("");
    private Image icon = null;
    private Label focus = new Label("");
    
    public CategoryRenderer(){
        setLayout(new BorderLayout());
        addComponent(BorderLayout.WEST, pic);
        Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));

        nameLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        nameLbl.getStyle().setBgTransparency(0);
        nameLbl.getStyle().setMargin(0, 0, 0, 0);

        descriptionLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_SMALL));
        descriptionLbl.getStyle().setBgTransparency(0);
        descriptionLbl.getStyle().setMargin(0, 0, 0, 0);

        pic.getStyle().setBgTransparency(0);
        cnt.addComponent(nameLbl);
        cnt.addComponent(descriptionLbl);

        addComponent(BorderLayout.CENTER, cnt);
        focus.getStyle().setBgTransparency(100);
        focus.getStyle().setBgColor(0xCCCCCC);
    }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
        try {
            icon = Image.createImage("/icons/categoryicon.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }       
        
        Category category = (Category) value;
        nameLbl.setText(category.getLabel());
        descriptionLbl.setText(category.getDescription());
        pic.setIcon(icon);
           
        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }

}
